package tests;

import static org.junit.Assert.*;

import java.sql.Timestamp;
import java.util.Date;



import model.Meeting;
import model.MeetingBuilder;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
 * This class tests the MeetingBuilder class
 * 
 * @author buthainahaldosary
 * @since June 5, 2013
 *
 * @version $Revision: 1.0 $
 */
public class TestMeetingBuilder {
	 MeetingBuilder mtBuilder,result,mtb;
	 Meeting mt;
	 Date date;
	 Timestamp currentTime;
	 
	 /**
		 * This method is called before every test case to setup a new meeting builder, date and current time timestamp.
		 */
	@Before
	public void setUp()
	{
		mtBuilder=new MeetingBuilder();
		date= new Date();
		currentTime=(new Timestamp(date.getTime()));
	}
	
	/**
	 * This method is called after every test case to tear down the MeetingBuilder and force garbage collection.
	 */
	@After
	public void tearDown()
	{
		mtBuilder=null;
		result=null;
		System.gc();	
	}

	/**
	 * This test case tests the setUserId() method 
	 */
	@Test
	public void testSetUserId() {
			result=mtBuilder.setUserId(2);
			assertEquals(2,result.getUserId());
	}
	

	
	/**
	 * This test case tests the setOwner method
	 */
	@Test
	public void testSetOwner() {
		result=mtBuilder.setOwner("sknarula");
		assertEquals("sknarula",result.getOwner());
	}
	
	/**
	 * This test case tests the setRevisionId() method 
	 */
	@Test
	public void testSetRevisionId() {
			result=mtBuilder.setRevisionId(2);
			assertEquals(2,result.getRevisionId());
	}
	
	/**
	 * This test case tests the setTopic method
	 */
	@Test
	public void testSetTopic() {
		result=mtBuilder.setTopic("new topic");
		assertEquals("new topic",result.getTopic());
	}
	
	/**
	 * This test case tests the getId method
	 */
	@Test
	public void testGetId() {
	result=new MeetingBuilder();
		assertEquals(-1,result.getId());
	}
	
	
	/**
	 * This test case tests the set location method
	 */
	@Test
	public void testSetLocation() {
		result=mtBuilder.setLocation("new location");
		assertEquals("new location",result.getLocation());
	}
	/**
	 * This test case tests the set start method
	 */
	@Test
	public void testSetStart() {
		date= new Date();
		currentTime=(new Timestamp(date.getTime()));
		result=mtBuilder.setStart(currentTime);
		assertEquals(currentTime,result.getStart());
	}
	/**
	 * This test case tests the set end method
	 */
	@Test
	public void testSetEnd() {
		date= new Date();
		currentTime=(new Timestamp(date.getTime()));
		result=mtBuilder.setEnd(currentTime);
		assertEquals(currentTime,result.getEnd());
	}
	/**
	 * This test case tests the set attendees method
	 */
	@Test
	public void testSetAttendees() {
		result=mtBuilder.setAttendees("new attendees");
		assertEquals("new attendees",result.getAttendees());
	}
	/**
	 * This test case tests the set description method
	 */
	@Test
	public void testSetDescription() {
		result=mtBuilder.setDescription("new description");
		assertEquals("new description",result.getDescription());
	}
	/**
	 * This test case tests the build method
	 */
	@Test
	public void testBuild() {
		mt=mtBuilder.setAttendees("attendees").setDescription("description").setEnd(currentTime).setEnd(currentTime).setTopic("topic").setUserId(1).build();
		assertNotNull(mt);
	}

}
